package com.nf;

import com.nf.spi.CalcInf;

import java.util.Iterator;
import java.util.ServiceLoader;

public class Main {
    public static void main(String[] args) {
        //basic();
        ServiceLoader<CalcInf> load = ServiceLoader.load(CalcInf.class);
        Iterator<CalcInf> iterator = load.iterator();
        while (iterator.hasNext()){
            CalcInf calcInf = iterator.next();
            int result = calcInf.doCalc(6, 7);
            System.out.println(result);
        }
    }

    private static void basic() {
        ServiceLoader<CalcInf> loader = ServiceLoader.load(CalcInf.class);
        Iterator<CalcInf> iterator = loader.iterator();


        //一个接口写了两个方法，一个类实现了接口的两个方法，类在测试时会只认为只有一个方法
        CalcInf calcInf = iterator.next();
        int i=calcInf.doCalc(5,6);
        System.out.println(i);

        CalcInf inf = iterator.next();
        int result = inf.doCalc2(78, 56);
        System.out.println(result);
    }
}
